package com.godfan.domain;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class MybatisUtils {
    private static SqlSessionFactory build;

    static {
        try {
            InputStream is = Resources.getResourceAsStream("MybatisConfig.xml");
            build = new SqlSessionFactoryBuilder().build(is);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static SqlSession getsqlSession() {
        return build.openSession();
    }
    public static SqlSession getsqlSession(boolean intocommet) {
        return build.openSession(intocommet);
    }
    public static void closs(SqlSession sqlSession){
        if (sqlSession!=null){
            sqlSession.close();
        }

    }
}
